package com.example.redis.domain.dto;



import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Description: 对象实体类
 * @author Bruce Lee
 * @date 2024/03/31
 */


@Data
public class TDevicePropertyReport {

    private Long deviceId;

    private Long currenttime;

    private int elevation;

    private int wirelessCommunication;

    private int oilVolume;

    private Integer[] alarm;

    private double latitude;

    private double longitude;

    private int positioningSatellitesNumber;

    private double speed;

    private double mileage;

    private String status;
    private double direction;
    private String alarmSign;
    private Long carId;
    private String carNum;


    public void convertAlarm(int alarmBit) {
        if(alarmBit==0){
            this.alarm = null;
            return;
        }
        String alarmDetail = Integer.toBinaryString(alarmBit);
        List<Integer> alarmSignList = new ArrayList<Integer>();
        for(int i=0;i<32;i++){
            if(alarmDetail.length()>i){
                char c = alarmDetail.charAt(alarmDetail.length()-1-i);
                if(c=='1'){
                    alarmSignList.add(i);
                }
            }
        }
        if(alarmSignList.size()>0){
            this.alarm =  alarmSignList.toArray(new Integer[alarmSignList.size()]);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TDevicePropertyReport report = (TDevicePropertyReport) o;
        return deviceId.equals(report.deviceId) && carId.equals(report.carId) && carNum.equals(report.carNum);
    }

    @Override
    public int hashCode() {
        return Objects.hash(deviceId, carId, carNum);
    }

}

